package stark.app.function.gobang;

import android.view.View;

import com.blankj.utilcode.util.ToastUtils;
import com.stark.gobang.lib.view.HumanChessView;

import stark.app.R;
import stark.app.databinding.FragmentGoBangHumanDemoBinding;
import stark.common.basic.base.BaseNoModelFragment;

public class GoBangHumanDemoFragment extends BaseNoModelFragment<FragmentGoBangHumanDemoBinding> {
    @Override
    protected int onCreate() {
        return R.layout.fragment_go_bang_human_demo;
    }

    @Override
    protected void initView() {
        mDataBinding.btHumanBatterAgain.setOnClickListener(this);
        mDataBinding.btHumanBatterRandomAuto.setOnClickListener(this);
        mDataBinding.btHumanBatterStartBlack.setOnClickListener(this);
        mDataBinding.btHumanBatterStartWhite.setOnClickListener(this);
        mDataBinding.btHumanBatterRegret.setOnClickListener(this);

        mDataBinding.humanChessView.setListener(new HumanChessView.IListener() {
            @Override
            public void onCurrentPlayer(boolean currentPlayer) {
                mDataBinding.tvHumanBatterCurrentPlayer.setText(currentPlayer ? "下一步为黑棋落子" : "下一步为白棋落子");
            }

            @Override
            public void onClickWin(boolean hasBlackWin) {
                if (hasBlackWin) {
                    ToastUtils.showShort("黑棋赢了");
                } else {
                    ToastUtils.showShort("白棋赢了");
                }
            }

            @Override
            public void onClickDraw() {
                ToastUtils.showShort("和棋");
            }
        });
    }

    @Override
    protected void initData() {

    }

    @Override
    public void onClick(View view) {
        int id = view.getId();
        if (id == R.id.btHumanBatterAgain) {
            mDataBinding.humanChessView.clear();
        } else if (id == R.id.btHumanBatterRandomAuto) {
            mDataBinding.humanChessView.autoChess();
        } else if (id == R.id.btHumanBatterStartBlack) {
            mDataBinding.humanChessView.startBlack();
        } else if (id == R.id.btHumanBatterStartWhite) {
            mDataBinding.humanChessView.startWhite();
        } else if (id == R.id.btHumanBatterRegret) {
            mDataBinding.humanChessView.regret();
        }
    }
}
